<?php

/*
 * This file will be used for setting up the pagination num bar.
 * 
 * Created by: Peter Agno Jr.
 * Date created: November 18, 2011
 * 
 * In parameters: columnNum - was set for the colspan of the paginationNumBar, appendTo - table on where it will be appended
 * Out parameters: none
 */
?>

    // START - CREATING THE PAGINATION NUMBER BAR
        // IF THERE IS ONLY ONE PAGE, THEN DON'T SHOW PAGINATION
        if ( pageNum != 1 ) {
            varRow = "<tr class='paginationNumBar'><td colspan='"+columnNum+"' align='center'><div class='paginationNumBarDiv'>";

            // IF THE ACCUMULATED (OR TOTAL) $pageNum > $viewPageNumLimit THEN SHOW ONLY $viewPageNumLimit OF PAGE NUMBERS, AND DON'T SHOW FIRST 
            if ( pageNum > viewPageNumLimit ) {
                varRow += "<input style='display:none;' class='paginationBtnCss paginationPageNumbers pageButton firstPageButton' id='rowPage_1' type='button' value='First' /> ";
                varRow += "<input style='display:none;' class='paginationBtnCss paginationPageNumbers pageButton prevPageButton' id='rowPage_1' type='button' value='Previous' /> ";

                for ( i = 1 ; i <= pageNum ; i++ ) {
                    if ( i <= viewPageNumLimit ) {
                        if ( firstRow == true ) {
                            firstRow = false;
                            varRow += "<input class='paginationCurrentPage ";
                        }
                        else {
                            varRow += "<input class='paginationPageNumbers ";
                        }
                    }
                    else {
                        varRow += "<input style='display:none;' class='paginationPageNumbers ";
                    }

                    varRow += "paginationBtnCss pageButton buttonNum_"+i+"' id='rowPage_"+i+"' type='button' value='"+i+"' /> ";
                }

                varRow += "<input class='paginationBtnCss paginationPageNumbers pageButton nextPageButton' id='rowPage_2' type='button' value='Next' /> ";
                varRow += "<input class='paginationBtnCss paginationPageNumbers pageButton lastPageButton' id='rowPage_"+pageNum+"' type='button' value='Last' /> ";
            }
            else {
            // ELSE, SHOW ALL PAGE NUMBERS
                for ( i = 1 ; i <= pageNum ; i++ ) {                    
                    if ( firstRow == true ) {
                        firstRow = false;
                        varRow += "<input class='paginationCurrentPage ";
                    }
                    else {
                        varRow += "<input class='paginationPageNumbers ";
                    }
                    
                    varRow += "paginationBtnCss pageButton buttonNum_"+i+"' id='rowPage_"+i+"' type='button' value='"+i+"' /> ";
                }
            }

            varRow += "</div></td></tr>";
            jQuery("."+appendTo).append(varRow);
        }

        jQuery("#totalPageNum").val(pageNum);
    // END - CREATING THE PAGINATION NUMBER BAR